﻿// Decompiled with JetBrains decompiler
// Type: System.Web.Razor.Parser.TextReaderExtensions
// Assembly: System.Web.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
// MVID: 682513D6-F37E-48AC-9909-F3EE103CFF14
// Assembly location: D:\Project\Idea\无人机外网\uav\客户端工程\排查工具\bin\Release\System.Web.Razor.dll

using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace System.Web.Razor.Parser
{
  internal static class TextReaderExtensions
  {
    public static string ReadUntil(this TextReader reader, char terminator) => reader.ReadUntil(terminator, false);

    public static string ReadUntil(this TextReader reader, char terminator, bool inclusive)
    {
      if (reader == null)
        throw new ArgumentNullException(nameof (reader));
      return reader.ReadUntil((Predicate<char>) (c => (int) c == (int) terminator), inclusive);
    }

    public static string ReadUntil(this TextReader reader, params char[] terminators) => reader.ReadUntil(false, terminators);

    public static string ReadUntil(
      this TextReader reader,
      bool inclusive,
      params char[] terminators)
    {
      if (reader == null)
        throw new ArgumentNullException(nameof (reader));
      if (terminators == null)
        throw new ArgumentNullException(nameof (terminators));
      return reader.ReadUntil((Predicate<char>) (c => ((IEnumerable<char>) terminators).Any<char>((Func<char, bool>) (tc => (int) tc == (int) c))), inclusive);
    }

    public static string ReadUntil(this TextReader reader, Predicate<char> condition) => reader.ReadUntil(condition, false);

    public static string ReadUntil(
      this TextReader reader,
      Predicate<char> condition,
      bool inclusive)
    {
      if (reader == null)
        throw new ArgumentNullException(nameof (reader));
      if (condition == null)
        throw new ArgumentNullException(nameof (condition));
      StringBuilder stringBuilder = new StringBuilder();
      int num;
      while ((num = reader.Peek()) != -1 && !condition((char) num))
      {
        reader.Read();
        stringBuilder.Append((char) num);
      }
      if (inclusive && reader.Peek() != -1)
        stringBuilder.Append((char) reader.Read());
      return stringBuilder.ToString();
    }

    public static string ReadWhile(this TextReader reader, Predicate<char> condition) => reader.ReadWhile(condition, false);

    public static string ReadWhile(
      this TextReader reader,
      Predicate<char> condition,
      bool inclusive)
    {
      if (reader == null)
        throw new ArgumentNullException(nameof (reader));
      if (condition == null)
        throw new ArgumentNullException(nameof (condition));
      return reader.ReadUntil((Predicate<char>) (ch => !condition(ch)), inclusive);
    }

    public static string ReadWhiteSpace(this TextReader reader) => reader.ReadWhile((Predicate<char>) (c => char.IsWhiteSpace(c)));

    public static string ReadUntilWhiteSpace(this TextReader reader) => reader.ReadUntil((Predicate<char>) (c => char.IsWhiteSpace(c)));
  }
}
